package com.ruoyi.cbs.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cbs.contract.domain.ContractorDocument;
import com.ruoyi.cbs.contract.service.IContractorDocumentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 承包商资料Controller
 * 
 * @author ruoyi
 * @date 2025-10-31
 */
@RestController
@RequestMapping("/contractor/document")
public class ContractorDocumentController extends BaseController
{
    @Autowired
    private IContractorDocumentService contractorDocumentService;

    /**
     * 查询承包商资料列表
     */
    @PreAuthorize("@ss.hasPermi('cbs:document:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractorDocument contractorDocument)
    {
        startPage();
        List<ContractorDocument> list = contractorDocumentService.selectContractorDocumentList(contractorDocument);
        return getDataTable(list);
    }

    /**
     * 导出承包商资料列表
     */
    @PreAuthorize("@ss.hasPermi('cbs:document:export')")
    @Log(title = "承包商资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractorDocument contractorDocument)
    {
        List<ContractorDocument> list = contractorDocumentService.selectContractorDocumentList(contractorDocument);
        ExcelUtil<ContractorDocument> util = new ExcelUtil<ContractorDocument>(ContractorDocument.class);
        util.exportExcel(response, list, "承包商资料数据");
    }

    /**
     * 获取承包商资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('cbs:document:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(contractorDocumentService.selectContractorDocumentById(id));
    }

    /**
     * 新增承包商资料
     */
    @PreAuthorize("@ss.hasPermi('cbs:document:add')")
    @Log(title = "承包商资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractorDocument contractorDocument)
    {
        contractorDocument.setCreateBy(getUsername());
        return toAjax(contractorDocumentService.insertContractorDocument(contractorDocument));
    }

    /**
     * 修改承包商资料
     */
    @PreAuthorize("@ss.hasPermi('cbs:document:edit')")
    @Log(title = "承包商资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractorDocument contractorDocument)
    {
        return toAjax(contractorDocumentService.updateContractorDocument(contractorDocument));
    }

    /**
     * 删除承包商资料
     */
    @PreAuthorize("@ss.hasPermi('cbs:document:remove')")
    @Log(title = "承包商资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(contractorDocumentService.deleteContractorDocumentByIds(ids));
    }
}
